package com.lzx.adx.report.controller.v1.cps.meituan;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lzs.adx.commmon.utils.DateUtils;
import com.lzs.adx.commmon.utils.JsonUtils;
import com.lzs.adx.commmon.utils.Result;
import com.lzx.adx.report.bean.mapper.MeiTuanMapper;
import com.lzx.adx.report.bean.mapper.ReportMapper;
import com.lzx.adx.report.cache.AccountLocalCache;
import com.lzx.adx.report.dto.AccountDTO;
import com.lzx.adx.report.dto.MeituanOrderDTO;
import com.lzx.adx.report.dto.ReportDTO;
import com.lzx.adx.report.dto.meituan.MeiTuanResponse;
import com.lzx.adx.report.entity.MeituanOrderEntity;
import com.lzx.adx.report.enums.ElmCovertKsEventTypeEnums;
import com.lzx.adx.report.model.ks.request.KsReportRequest;
import com.lzx.adx.report.model.meituan.OrderCallBackRequest;
import com.lzx.adx.report.service.MeituanOrderService;
import com.lzx.adx.report.service.ReportService;
import com.lzx.adx.report.util.UrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 快手美团CPS
 */
@RestController
@RequestMapping("/ks/mt")
@Slf4j
public class KsMeiTuanController {

    @Resource
    private MeituanOrderService meituanOrderService;

    @Autowired
    private MeiTuanMapper tuanMapper;

    @Autowired
    private ReportMapper reportMapper;

    @Autowired
    private ThreadPoolTaskExecutor reportExecutor;

    @Resource
    private ReportService reportService;





    @GetMapping("/report")
    public ResponseEntity report(KsReportRequest ksReportRequest) {
        log.info("快手->美团上报请求的参数为{}", JSON.toJSONString(ksReportRequest));
        //广点通，转换
        ReportDTO reportDTO=reportMapper.toReportKsReportDTO(ksReportRequest);
        reportDTO.setBizRequestId(IdUtil.fastUUID());
        reportDTO.setCreateTime(new Date());
        reportDTO.setUpdateTime(new Date());
        reportDTO.setExtend(JSON.toJSONString(ksReportRequest));
        reportExecutor.execute(()->{
            reportService.saveData(reportDTO);
        });

        return ResponseEntity.ok(new Result());
    }






}
